/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2013/03/16
* File: MaterialBase.cpp
* Blog: http://www.cnblogs.com/zengqh/
**/

#include "MaterialBase.h"

namespace HY
{

static const std::string MaterialBase::diffuse_map_ = "DiffuseMap";
static const std::string MaterialBase::light_map_ = "LightMap";
static const std::string MaterialBase::ambient_occlusion_map_ = "AmbientOcclusionMap";
static const std::string MaterialBase::emissive_map_ = "EmissiveMap";
static const std::string MaterialBase::reflection_map_ = "ReflectionMap";
static const std::string MaterialBase::reflectivity_map_ = "ReflectivityMap";
static const std::string MaterialBase::normal_map_ = "NormalMap";
static const std::string MaterialBase::specular_map_ = "SpecularMap";
static const std::string MaterialBase::height_map_ = "HeightMap";

MaterialBase::MaterialBase(const std::string& name)
: name_(name)
{

}

MaterialBase::~MaterialBase()
{

}

Parameter* MaterialBase::getParameter(const std::string& name) const
{
	Parameter* param = param_mgr_->getParam(name);
	if (param)
	{
		return param;
	}
	else
	{
		for (uint32 i = 0; i < mat_list_.size(); ++i)
		{
			const MaterialBase* mat = mat_list_[i];
			if (mat)
			{
				param = mat->getParameter(name);
				if (param)
				{
					return param;
				}
			}
		}
	}

	return 0;
}

uint32 MaterialBase::getNumofMaterial() const
{
	return mat_list_.size();
}

bool MaterialBase::addMaterial(MaterialBase& mat)
{
	mat_list_.push_back(&mat);
}

MaterialBase* MaterialBase::getMaterial(uint32 idx) const
{
	return mat_list_[idx];
}

bool MaterialBase::removeMaterial(uint32 idx)
{
	mat_list_.erase(mat_list_.begin() + idx);
}

bool MaterialBase::removeAllMaterial()
{
	for (int i = 0; i < mat_list_.size(); ++i)
	{
		MaterialBase* mat = mat_list_[i];

		HY_SAFE_DELETE(mat);
	}

	mat_list_.clear();
}

Effect* MaterialBase::getEffect() const
{
	return fx_;
}

void MaterialBase::setEffect(Effect* fx)
{
	fx_ = fx;
}

uint32 MaterialBase::getNumOfPass() const
{

}

bool MaterialBase::setupPass(uint32 idx = 0) const;

bool MaterialBase::loadByFileName(const std::string& file_name);

}